import page from '../../databus/page'
import positionsAddTpl from '../../views/positions/positions-add.art'
import { positionsAdd as positionsAddModel } from '../../models/positions'

// 添加用户
export const addPosition = () => {
  // return (e) => {
  //   console.log(222)
  // }
  
  const html = positionsAddTpl()
  $('#positions-list-box').after(html)
    
  const _save = async () => {
    // 提交表单
    // const data = $('#positions-form').serialize()
    // let res = await positionsAddModel(data)
    let res = await positionsAddModel()
    try {
      if(res.ret) {
        alert(res.data.message)
        page.setCurPage(1)
        // _loadData() // 添加数据后渲染
        $('body').trigger('addPosition')
        $('#positions-close').click()
      } else {
        alert(res.data.message)
      }
    } catch (err) {
      console.log(err)
    }
  }
    
  // 点击保存，提交表单
  $('#positions-save').on('click',  _save)
}
